package com.gxa.service.discrepancy.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.entity.discrepancy.Audit;
import com.gxa.entity.discrepancy.Device;
import com.gxa.entity.discrepancy.DeviceLog;
import com.gxa.entity.discrepancy.search.AudiSearchMap;
import com.gxa.entity.discrepancy.search.DeviceSearchMap;
import com.gxa.mapper.discrepancy.AuditMapper;
import com.gxa.service.discrepancy.AuditService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yjl
 * @since 2022-10-12 11:43:53
 */
@Service
public class AuditServiceImpl extends ServiceImpl<AuditMapper, Audit> implements AuditService {

    @Autowired
    private AuditMapper mapper;

    @Override
    public PageInfo<Audit> queryByPage(AudiSearchMap map) {
        PageHelper.startPage(map.getPageNum(),map.getPageSize());//1.开启分页

        QueryWrapper<Audit> wrapper = new QueryWrapper<>();//2.条件构造器 模拟写动态sql  或者在xml 中写
        if (!StringUtils.isAnyBlank(map.getVisitorName())) {
            wrapper.like("visitors_name", map.getVisitorName());
        }
        if (!StringUtils.isAnyBlank(map.getPhone())) {
            wrapper.like("visitors_phone", map.getPhone());
        }
        if (!StringUtils.isAnyBlank(map.getIdCard())) {
            wrapper.like("id_card", map.getIdCard());
        }
        if (!StringUtils.isAnyBlank(map.getCarNum())) {
            wrapper.like("car_number", map.getCarNum());
        }
        if (map.getApplyStatus() != null) {
            wrapper.eq("audit_status", map.getApplyStatus());
        }

        if(!StringUtils.isAnyBlank(map.getStartTime(),map.getEndTime())){
            wrapper.between("appointment_time",map.getStartTime(),map.getEndTime());
        }
        PageInfo<Audit> pageInfo = new PageInfo<>(mapper.selectList(wrapper));//3.获取分页信息
        return pageInfo;
    }
}
